﻿#region  文件信息
// ---------------------------------------------------------------------------------------
// <copyright file="JsonReturn.cs" company="">
// 作者：李帅伦
// </copyright>
// <summary>
// 类型简介：
// 类型详细：JsonReturn.cs
// 创建时间：2014-10-28 15:30
// 修改时间：2014-10-28 15:30
// </summary>
// ---------------------------------------------------------------------------------------
#endregion

using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;

namespace LsTool
{
    [JsonObject(MemberSerialization.OptOut)]
    public class JsonReturn 
    { 
        public string Url { get; set; }
        /// <summary>
        /// 数据
        /// </summary> 
        public object ModelData { get; set; }
        /// <summary>
        /// 状态代码
        /// </summary> 
        public int Code { get; set; }
        /// <summary>
        /// 代码消息
        /// </summary> 
        public string CodeMs { get; set; }
         
        public string Timestamp { get; set; }
        /// <summary>
        /// 构造( Code = "0"; CodeMs = "正常";)
        /// </summary>
        public JsonReturn()
        {
            this.Code = 0; 
            this.Url = "/";
            this.Timestamp = DateTime.Now.Ticks.ToString();

            //var json =   ContentType.json;

        }
        /// <summary>
        /// 构造( Code = "0"; CodeMs = "正常";)
        /// </summary>
        /// <param name="data">JSON数据模型</param>
        public JsonReturn(object data)
            : this()
        {
            this.ModelData = data;

        }

        /// <summary>
        /// 构造( Code = "0"; CodeMs = "正常";)
        /// </summary> 
        /// <param name="dataJson">JSON</param>
        public JsonReturn(string dataJson)
            : this()
        {
            this.ModelData = JObject.Parse(dataJson).ToObject<object>();
        }




        /// <summary>
        /// TOJson
        /// </summary>
        /// <returns></returns>
        private string ToJson()
        {
            IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
            timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; 
            return JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented, timeFormat);
        }

      
    }
}